package com.example.everying.controller.content;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.everying.model.entity.content.ActivityAudit;
import com.example.everying.model.vo.content.ActivityAuditVo;
import com.example.everying.service.content.ActivityAuditService;
import com.example.everying.utils.PageParam;
import com.example.everying.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @program: everything
 * @description: 审核记录
 * @author: zw
 * @create: 2025-05-17 10:37
 **/
@Slf4j
@RestController
@Api(tags = "审核记录")
@RequestMapping("/activity/audit")
public class ActivityAuditController {

    @Autowired
    private ActivityAuditService auditService;

    //条件查询带分页
    @ApiOperation(value = "分页查询")
    @PostMapping("/page")
    public Result list(@RequestBody PageParam<ActivityAuditVo> query) {
        Page<ActivityAudit> pageParam = new Page<>(query.getPage(), query.getLimit());
        IPage<ActivityAudit> pageModel = auditService.selectPage(pageParam, query.getQuery());
        return Result.ok(pageModel);
    }

    @ApiOperation(value = "手动添加内容")
    @PostMapping("auditAdd")
    public Result auditAdd(@ApiParam(name = "ActivityAuditVo", value = "内容对象", required = true)
                             @RequestBody ActivityAuditVo auditVo) {
        ActivityAudit article = new ActivityAudit();
        BeanUtil.copyProperties(auditVo, article);
        boolean save = auditService.save(article);
        if (save) {
            return Result.ok(article.getId().toString());
        } else {
            return Result.fail();
        }
    }

    @ApiOperation(value = "修改")
    @ApiParam(name = "id", value = "id", required = true)
    @PostMapping("auditEdit")
    public Result articleEdit(@ApiParam(name = "ActivityAuditVo", value = "内容对象", required = true)
                              @RequestBody ActivityAuditVo auditVo) {
        ActivityAudit audit = new ActivityAudit();
        BeanUtil.copyProperties(auditVo, audit);
        auditService.updateById(audit);
        return Result.ok();
    }

}
